/*
 * Created by JFormDesigner on Wed Jun 14 20:55:18 CST 2023
 */

package fm.type;

import dao.Dao_trade;
import dao.Dao_type;
import model.TradeType;

import java.awt.*;
import java.awt.event.*;
import java.util.List;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.table.DefaultTableModel;

/**
 * @author YangC
 */
public class LookType extends JInternalFrame {
    String [] columns = {"类别编号","类别名称","上限","下限"};

    private Object [][] getFS(List list)
    {
        Object [][] results = new Object[list.size()][columns.length];

        for(int i = 0; i < list.size(); i++)
        {
            TradeType type = (TradeType) list.get(i);

            results[i][0] = type.getType_id();
            results[i][1] = type.getType_name();
            results[i][3] = type.getMin();
            results[i][2] = type.getMax();
        }
        return results;
    }


    public LookType() {
        initComponents();
        iniData();
    }

    public void iniData() {
        Object[][] results = getFS(Dao_type.selectAll());
        DefaultTableModel model = new DefaultTableModel(results, columns);
        table.setModel(model);
    }

    private void back(ActionEvent e) {
        // TODO add your code here
        doDefaultCloseAction();
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        panel1 = new JPanel();
        backButton = new JButton();
        panel2 = new JPanel();
        scrollPane1 = new JScrollPane();
        table = new JTable();

        //======== this ========
        setVisible(true);
        setIconifiable(true);
        setClosable(true);
        setTitle("\u67e5\u770b\u4fe1\u606f");
        var contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());

        //======== panel1 ========
        {
            panel1.setPreferredSize(new Dimension(280, 30));
            panel1.setLayout(null);

            //---- backButton ----
            backButton.setText("\u8fd4\u56de");
            backButton.addActionListener(e -> back(e));
            panel1.add(backButton);
            backButton.setBounds(195, -1, 85, backButton.getPreferredSize().height);

            {
                // compute preferred size
                Dimension preferredSize = new Dimension();
                for(int i = 0; i < panel1.getComponentCount(); i++) {
                    Rectangle bounds = panel1.getComponent(i).getBounds();
                    preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                    preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                }
                Insets insets = panel1.getInsets();
                preferredSize.width += insets.right;
                preferredSize.height += insets.bottom;
                panel1.setMinimumSize(preferredSize);
                panel1.setPreferredSize(preferredSize);
            }
        }
        contentPane.add(panel1, BorderLayout.SOUTH);

        //======== panel2 ========
        {
            panel2.setBorder(new TitledBorder("\u5546\u54c1\u7c7b\u522b\u4fe1\u606f"));
            panel2.setLayout(null);

            //======== scrollPane1 ========
            {
                scrollPane1.setViewportView(table);
            }
            panel2.add(scrollPane1);
            scrollPane1.setBounds(10, 20, 445, 315);

            {
                // compute preferred size
                Dimension preferredSize = new Dimension();
                for(int i = 0; i < panel2.getComponentCount(); i++) {
                    Rectangle bounds = panel2.getComponent(i).getBounds();
                    preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                    preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                }
                Insets insets = panel2.getInsets();
                preferredSize.width += insets.right;
                preferredSize.height += insets.bottom;
                panel2.setMinimumSize(preferredSize);
                panel2.setPreferredSize(preferredSize);
            }
        }
        contentPane.add(panel2, BorderLayout.CENTER);
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JPanel panel1;
    private JButton backButton;
    private JPanel panel2;
    private JScrollPane scrollPane1;
    private JTable table;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
